<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<form:form commandName="taskUnit" cssClass="form-horizontal" role="form">
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" readonly for="taskSubName">议题内容</label>
        <div class="col-sm-8">
            <textarea type="text" id="taskSubName"
                      class="form-control" readonly>${taskUnit.taskSubName}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" readonly>承办单位</label>
        <div class="col-sm-3">
            <input type="text"
                   class="form-control" value="${taskUnit.deptName}" readonly>
        </div>
        <label class="col-sm-2 control-label no-padding-right" readonly >单位类型</label>
        <div class="col-sm-3">
            <input type="text"
                   class="form-control" value="${taskUnit.unitType == 1 ? '牵头' : taskUnit.unitType == 2 ? '主办': taskUnit.unitType == 3 ? '协办' : taskUnit.unitType == 4 ? '分办' : taskUnit.unitType == 5 ? '独办' : '未知'}" readonly>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" readonly>任务时限</label>
        <div class="col-sm-3">
            <input type="text"
                   class="form-control" value="${taskUnit.timeLimit}" readonly>
        </div>
        <label class="col-sm-2 control-label no-padding-right" readonly >任务状态</label>
        <div class="col-sm-3">
            <input type="text" id="type"
                   class="form-control" value="${taskUnit.type == 0 ? '待签收' :taskUnit.type == 1 ? '待反馈' : taskUnit.type == 2 ? '已反馈': taskUnit.type == 3 ? '退回重办' : taskUnit.type == 4 ? '完成' : '未知'}" readonly>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-2">
            <input type="button" class="btn-sm btn-success" onclick="addcompany()" value="添加">
        </div>
    </div>
    <div id="jbrContent">
    </div>

    <input type="hidden" name="sysId" value="${taskUnit.sysId}">

</form:form>
<script src="<s:url value="/assets/js/chosen.jquery.js"></s:url>"></script>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script src="<s:url value="/assets/js/modal/modal.js"></s:url>"></script>

<script type="text/javascript">

    // 单位经办人option字符串
    var i =  0;
    var operatorOption = '<option value="">点击选择</option>';
    // 获取单位责任人
    (function () {
        $.ajax({
            type: "post",
            url: getUrl("unitUser"),
            dataType: "json",
            success: function (data) {
                if (data == undefined || data == null) {
                    return alert("获取单位责任人为空");
                }
                for (var i = 0; i < data.length; i++) {
                    var name = data[i].name;
                    var sysId = data[i].sysId;
                    var mobile = data[i].mobile;
                    operatorOption += '<option value="' + sysId + '" mobile="'+ mobile +'">' + name + '</option>';
                }
            },
        });
    })();
    //插入html页面中
    function addcompany() {
        var html="";
        html +=  "<div class=\"form-group\">\n" +
            "<div class=\"form-group\">\n" +
            "            <label class=\"col-sm-2 control-label no-padding-right\" readonly for=\"content\">内容</label>\n" +
            "            <div class=\"col-sm-8\">\n" +
            "                <textarea type=\"text\" rows=\"1\" id=\"content\" name=\"taskUserList["+ i +"].content\"\n" +
            "                          class=\"form-control\" placeholder=\"请输入内容\"></textarea>\n" +
            "            </div>\n" +
            "        </div>" +
            "<div class=\"form-group\">\n" +
            "            <label class=\"col-sm-2 control-label no-padding-right\" readonly>承办人</label>\n" +
            "   <div class=\"col-sm-3\">\n" +
            "            <select name=\"taskUserList["+ i +"].unitUserId\" class=\"form-control\">\n" +
            "                  " + operatorOption + "\n" +
            "            </select>\n" +
            "   </div>\n" +
            "            <label class=\"col-sm-2 control-label no-padding-right\" readonly>电话</label>\n" +
            "   <div class=\"col-sm-3\">\n" +
            "            <input type=\"text\" value=\" \" class=\"form-control\" readonly>\n" +
            "   </div>\n" +
            "<div class='col-sm-1'>" +
            "         <button class='btn-sm btn-danger deleteRow'>删除</button>" +
            "</div>" +
            "</div>" +
            " </div>"
        $('#jbrContent').append(html);
        i+=1;
    }
    $(document).on("change","select",function () {
        var $this = $(this);
        $this.parent("div").siblings("div").children("input").val($this.find("option:selected").attr('mobile'));
    })
    $(document).on("click",".deleteRow",function () {
        var $this = $(this);
        $this.parent().parent().parent().remove();
    })
</script>
